import axios from "axios";
import { getToken } from '@/utils/auth'
const BASEURL = "http://8.129.161.191:8848/";
// const BASEURL = "http://localhost:8848/";
const instance = axios.create({
  baseURL: BASEURL,
});
instance.interceptors.request.use(
  function (config) {
    // 是否需要设置 token
      const isToken = (config.headers || {}).isToken === false
      // 是否需要防止数据重复提交
      const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
      if (getToken() && !isToken) {
        config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
      }
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

instance.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);
export default instance;
